package com.IT.controller;

import com.IT.constent.MessageConst;
import com.IT.entity.PageResult;
import com.IT.entity.QueryPageBean;
import com.IT.entity.Result;
import com.IT.pojo.CheckGroup;
import com.IT.service.CheckGroupService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    CheckGroupService checkGroupService;

    @RequestMapping("/add")
    public Result add(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        try {
            checkGroupService.add(checkGroup, checkitemIds);
            return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConst.ADD_CHECKGROUP_FAIL);
        }
    }

    //    @RequestMapping("/add")
//    public Result add(@RequestBody Map<String, Object> map) {
//        JSONObject jsonObject = (JSONObject) map.get("checkGroup");
//        //把JSONObject包的json串转换为对象
//        CheckGroup checkGroup = jsonObject.toJavaObject(CheckGroup.class);
//        System.out.println("checkGroup = " + checkGroup);
//
//       JSONArray jsonArray = (JSONArray) map.get("checkitemIds");
//       //JSONArray包json串转换为数组对象
//       Integer[] checkitemIds =jsonArray.toArray(new Integer[]{} );
//        System.out.println("checkitemIds = " + checkitemIds);
//        return null;
//    }
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkGroupService.queryPage(queryPageBean);
        return pageResult;
    }
}

